1 / 10

RMI over IIOP

RMI over IIOP. Remote object model is RMI Underlying transport is IIOP Talk to other CORBA objects if remote interfaces defined as RMI interfaces EJB clients interact with the J2EE EJB tier using the RMI-IIOP protocol. //HelloInterface.java import java.rmi.Remote;

nathan
Download Presentation

RMI over IIOP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. RMI over IIOP

  2. Remote object model is RMI • Underlying transport is IIOP • Talk to other CORBA objects if remote interfaces defined as RMI interfaces • EJB clients interact with the J2EE EJB tier using the RMI-IIOP protocol.

  3. //HelloInterface.java import java.rmi.Remote; public interface HelloInterface extends java.rmi.Remote { public void sayHello( String from ) throws java.rmi.RemoteException; }

  4. //HelloImpl.java import javax.rmi.PortableRemoteObject; //PortableRemoteObject means remote object that uses IIOP-based transport public class HelloImpl extends PortableRemoteObject implements HelloInterface { public HelloImpl() throws java.rmi.RemoteException { super(); // invoke rmi linking and remote object initialization } public void sayHello( String from ) throws java.rmi.RemoteException { System.out.println( "Hello from " + from + "!!" ); System.out.flush(); } }

  5. //HelloServer.java import javax.naming.InitialContext; import javax.naming.Context; public class HelloServer { public static void main(String[] args) { try { // Step 1: Instantiate the Hello servant HelloImpl helloRef = new HelloImpl(); // Step 2: Publish the reference in the Naming Service // using JNDI API (part of orbd) Context initialNamingContext = new InitialContext(); initialNamingContext.rebind("HelloService", helloRef ); System.out.println("Hello Server: Ready..."); } catch (Exception e) { System.out.println("Trouble: " + e); e.printStackTrace(); } } }

  6. //HelloClient.java import java.rmi.RemoteException; import java.net.MalformedURLException; import java.rmi.NotBoundException; import javax.rmi.*; import java.util.Vector; import javax.naming.NamingException; import javax.naming.InitialContext; import javax.naming.Context; public class HelloClient { public static void main( String args[] ) { Context ic; Object objref; HelloInterface hi; try { ic = new InitialContext(); // STEP 1: Get the Object reference from the Name Service // using JNDI call. objref = ic.lookup("HelloService"); System.out.println("Client: Obtained a ref. to Hello server."); // STEP 2: Narrow the object reference to the concrete type and // invoke the method. hi = (HelloInterface) PortableRemoteObject.narrow( objref, HelloInterface.class); hi.sayHello( " MARS " ); } catch( Exception e ) { System.err.println( "Exception " + e + "Caught" ); e.printStackTrace( ); return; } } }

  7. javac -d . -classpath . HelloImpl.java • rmic -iiop HelloImpl • javac -d . -classpath . HelloInterface.java HelloServer.java HelloClient.java • orbd -ORBInitialPort 1050& • java -classpath . -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory -Djava.naming.provider.url=iiop://localhost:1050 HelloServer • java -classpath . -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory -Djava.naming.provider.url=iiop://localhost:1050 HelloClient

  8. //HelloServer.java import javax.naming.InitialContext; import javax.naming.Context; import javax.rmi.PortableRemoteObject ; //Please note that internal Sun APIs //may change in future releases. import com.sun.corba.se.internal.POA.POAORB; import org.omg.PortableServer.*; import java.util.*; import org.omg.CORBA.*; import javax.rmi.CORBA.Stub; import javax.rmi.CORBA.Util; public class HelloServer { public HelloServer(String[] args) { try { Properties p = System.getProperties(); // add runtime properties here //Please note that the name of the servertool //class may change in future releases. p.put("org.omg.CORBA.ORBClass", "com.sun.corba.se.internal.POA.POAORB"); p.put("org.omg.CORBA.ORBSingletonClass", "com.sun.corba.se.internal.corba.ORBSingleton"); ORB orb = ORB.init( args, p ); POA rootPOA = (POA)orb.resolve_initial_references("RootPOA");

  9. // STEP 1: Create a POA with the appropriate policies Policy[] tpolicy = new Policy[3]; tpolicy[0] = rootPOA.create_lifespan_policy( LifespanPolicyValue.TRANSIENT ); tpolicy[1] = rootPOA.create_request_processing_policy( RequestProcessingPolicyValue.USE_ACTIVE_OBJECT_MAP_ONLY ); tpolicy[2] = rootPOA.create_servant_retention_policy( ServantRetentionPolicyValue.RETAIN); POA tPOA = rootPOA.create_POA("MyTransientPOA", null, tpolicy); // STEP 2: Activate the POA Manager, otherwise all calls to the // servant hang because, by default, POAManager will be in the // HOLD state. tPOA.the_POAManager().activate(); // STEP 3: Instantiate the Servant and activate the Tie, If the // POA policy is USE_ACTIVE_OBJECT_MAP_ONLY HelloImpl helloImpl = new HelloImpl(); _HelloImpl_Tie tie = (_HelloImpl_Tie)Util.getTie( helloImpl ); String helloId = "hello"; byte[] id = helloId.getBytes(); tPOA.activate_object_with_id( id, tie );

  10. // STEP 4: Publish the object reference using the same object id // used to activate the Tie object. Context initialNamingContext = new InitialContext(); initialNamingContext.rebind("HelloService", tPOA.create_reference_with_id(id, tie._all_interfaces(tPOA,id)[0]) ); System.out.println("Hello Server: Ready..."); // STEP 5: Get ready to accept requests from the client orb.run(); } catch (Exception e) { System.out.println("Problem running HelloServer: " + e); e.printStackTrace(); } } public static void main(String args[]) { new HelloServer( args ); } }

More Related